package com.qf.smsplatform.security;

import com.qf.smsplatform.mapper.TAdminUserMapper;
import com.qf.smsplatform.pojo.MyAuthUser;
import com.qf.smsplatform.pojo.TAdminUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;


@Service
public class MyUserDetailsService  implements UserDetailsService {

    private TAdminUserMapper userMapper;

    @Autowired
    public void setUserMapper(TAdminUserMapper userMapper) {
        this.userMapper = userMapper;
    }


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        TAdminUser user = userMapper.selectUserByUsercode(username);//从数据库中查询当前用户的信息
        MyAuthUser authUser=new MyAuthUser(username, user.getPassword(), new ArrayList<>());//将用户信息返回,主要就是密码
        authUser.setId(user.getId());//需要相应的参数，然后使用了继承进行功能扩展
        authUser.setType(user.getType());
        return authUser;
    }
}
